package com.atguigu.crud.service;

import com.atguigu.crud.bean.Command;
import com.atguigu.crud.bean.CommandExample;
import com.atguigu.crud.dao.CommandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service("commandService")
public class CommandService {
	@Autowired
	private CommandMapper commandMapper;
	
    //条件查询交易记录
	public List<Command> getAllByPars(Command rec) {
		CommandExample r = new CommandExample();
		CommandExample.Criteria c=r.createCriteria();
		 r.setOrderByClause("cretim desc");
		 return commandMapper.selectByExample(r);
	}
// id 查询对象
	public Command getRecord(String id) {
		System.out.println("参数id为："+id);
		return commandMapper.selectByPrimaryKey(id);
	}
   // 保存
	public void saveRec(Command command) {
		command.setId(UUID.randomUUID().toString());
		command.setCretim(new Date());
		commandMapper.insertSelective(command);
	}
//通过id删除
	public void delByid(String id) {
		commandMapper.deleteByPrimaryKey(id);
	}
//更新信息
	public void updateRec(Command command) {
		commandMapper.updateByPrimaryKeySelective(command);
	}
}
